#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>

void* thread_func(void* arg) {
    long id = (long) arg;
    printf("hello from id: %d\n", id);
    return 0;
}

int main(int argc, char** argv) {
    long count = atoi(argv[1]);
    pthread_t* thread_handles = (pthread_t*) malloc(count * sizeof(pthread_t));
    long thread;
    for (thread = 0; thread < count; ++thread) {
        pthread_create(&thread_handles[thread], NULL, thread_func, (void*)thread);
    }
    printf("hello from main thread.\n");
    for (thread = 0; thread < count; ++thread) {
        void* ret;
        pthread_join(thread_handles[thread], &ret);
        printf("ret: %ld\n", (long)(ret));
    }
    free(thread_handles);
    return 0;
}
